var path = require('path');
var webpack = require('webpack');

var APP_PATH = path.resolve(__dirname, './src/RaAmendRecordEditor.jsx');
var BUILD_PATH = path.resolve(__dirname, './dist');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
    entry: [APP_PATH],
    output: {
        path: BUILD_PATH,
        filename: "RaAmendRecordEditor.js",
        library: 'RaAmendRecordEditor',
		libraryTarget: 'umd'
    },
    externals:[
        {
            react: {
              root: 'React',
              commonjs2: 'react',
              commonjs: 'react',
              amd: 'react',
              umd: 'react',
            },
            'react-dom': {
              root: 'ReactDOM',
              commonjs2: 'react-dom',
              commonjs: 'react-dom',
              amd: 'react-dom',
              umd: 'react-dom',
            }
        },
        /^material-ui(\/.+)?$/
    ],
    resolve: {
    	extensions: [".js", ".jsx", ".css", ".less"]
    },
    module: {
        loaders: [
            {
              test: /\.jsx$/,
              exclude: /node_modules/,
              loader: "babel-loader",
              query:
                {
                  presets:['react','es2015']
                }
            }, {
                test: /\.less$/,
                loaders: ['style-loader','css-loader','less-loader']
            }, {
                test: /\.(png|jpg)$/,
                loader: 'url?limit=40000'
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin(BUILD_PATH),
        new UglifyJSPlugin({
            uglifyOptions:{
                output: {
                    comments: false
                },
                compress: {
                    warnings: false
                }
            }
        }),
        new webpack.DefinePlugin({
            'process.env': {
              'NODE_ENV': JSON.stringify('production')
            }
        })
    ]
};
